package com.example.studentregistration.util;

import lombok.Data;

import java.io.Serializable;

//统一封装返回结果类

@Data
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    //状态码
    private Integer code;//200是正常，非200表示异常
    //提示信息
    private String message;
    //数据
    private T data;
    //构造方法
    public Result() {
    }
    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }
    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    //请求成功
    public static <T> Result<T> success() {
        return new Result<T>(200, "操作成功！");
    }
    //请求成功，有数据
    public static <T> Result<T> success(T data) {
        return new Result<T>(200, "操作成功！", data);
    }
    //请求失败
    public static <T> Result<T> fail(String message) {
        return new Result<T>(500, message);
    }
}
